home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / gt64_diag.c < prev    next >
C/C++ Source or Header  |  2001-04-11  |  27KB  |  591 lines

  1. ////////////////////////////////////////////////////////////////
  2. // File - GT64_DIAG.C
  3. //
  4. // o A simple diagnostics program that lets you access the
  5. //   Galileo 64 registers and local memory. 
  6. // o This program is meant to be used as an example for using the GT64_LIB.H API,
  7. //   you may use it as a skeleton for your driver, or 'cut & paste' parts
  8. //   of it into your device driver code.
  9. // 
  10. ////////////////////////////////////////////////////////////////
  11.  
  12. #include "../../../include/windrvr.h"
  13. #include "../lib/gt64_lib.h"
  14. #include "../../../samples/shared/pci_diag_lib.h"
  15. #include <stdio.h>
  16.  
  17. // input of command from user
  18. static char line[256];
  19.  
  20. void GT64_EditReg(GT64_HANDLE hGT)
  21. {
  22.     struct 
  23.     {
  24.         CHAR *name;
  25.         DWORD dwOffset;
  26.         DWORD dwVal;
  27.     } fields[160];
  28.     struct
  29.     {
  30.         CHAR *name;
  31.         int iPosition;
  32.     } group[20];
  33.  
  34.     int cmd, cmd2;
  35.     int i = 0;
  36.     int j = 0;
  37.     int iGroupNum;
  38.     int iFieldsNum;
  39.     BOOL f111 = hGT->gt64Ver==GT64_VERSION_64111;
  40.     BOOL f120 = hGT->gt64Ver==GT64_VERSION_64120;
  41.     BOOL f130 = hGT->gt64Ver==GT64_VERSION_64130;
  42.  
  43.     // CPU/Local Master Interface Configuration
  44.     group[j].name ="CPU/Local Master Interface Configuration"; group[j++].iPosition = i;
  45.     fields[i].name ="CPU/Local Master Interface Configuration"; fields[i++].dwOffset = 0x000;
  46.     if (f120 || f130) 
  47.     {
  48.         fields[i].name ="Multi-GT Register"; fields[i++].dwOffset = 0x120;
  49.     }
  50.     // Processor Address Space
  51.     group[j].name ="Processor Address Space"; group[j++].iPosition = i;
  52.     fields[i].name ="RAS[1:0] Low Decode Address"; fields[i++].dwOffset = 0x008;
  53.     fields[i].name ="RAS[1:0] High Decode Address"; fields[i++].dwOffset = 0x010;
  54.     fields[i].name ="RAS[3:2] Low Decode Address"; fields[i++].dwOffset = 0x018;
  55.     fields[i].name ="RAS[3:2] High Decode Address"; fields[i++].dwOffset = 0x020;
  56.     fields[i].name ="CS[2:0] Low Decode Address"; fields[i++].dwOffset = 0x028;
  57.     fields[i].name ="CS[2:0] High Decode Address"; fields[i++].dwOffset = 0x030;
  58.     fields[i].name ="CS[3] & Boot CS Low Decode Address"; fields[i++].dwOffset = 0x038;
  59.     fields[i].name ="CS[3] & Boot CS High Decode Address"; fields[i++].dwOffset = 0x040;
  60.     fields[i].name ="PCI I/O Low Decode Address"; fields[i++].dwOffset = 0x048;
  61.     fields[i].name ="PCI I/O High Decode Address"; fields[i++].dwOffset = 0x050;
  62.     fields[i].name ="PCI Memory 0 Low Decode Address"; fields[i++].dwOffset = 0x058;
  63.     fields[i].name ="PCI Memory 0 High Decode Address"; fields[i++].dwOffset = 0x060;
  64.     fields[i].name ="Internal Space Decode"; fields[i++].dwOffset = 0x068;
  65.     fields[i].name ="Bus Error Address Low Processor"; fields[i++].dwOffset = 0x070;
  66.     fields[i].name ="Read Only 0"; fields[i++].dwOffset = 0x078;
  67.     fields[i].name ="PCI Memory 1 Low Decode Address"; fields[i++].dwOffset = 0x080;
  68.     fields[i].name ="PCI Memory 1 High Decode Address"; fields[i++].dwOffset = 0x088;
  69.     if (f120 || f130)
  70.     {
  71.         fields[i].name ="PCI_1 I/O Low Decode Address"; fields[i++].dwOffset = 0x090;
  72.         fields[i].name ="PCI_1 I/O High Decode Address"; fields[i++].dwOffset = 0x098;
  73.         fields[i].name ="PCI_1 Memory 0 Low Decode Address"; fields[i++].dwOffset = 0x0a0;
  74.         fields[i].name ="PCI_1 Memory 0 High Decode Address"; fields[i++].dwOffset = 0x0a8;
  75.         fields[i].name ="PCI_1 Memory 1 Low Decode Address"; fields[i++].dwOffset = 0x0b0;
  76.         fields[i].name ="PCI_1 Memory 1 High Decode Address"; fields[i++].dwOffset = 0x0b8;
  77.         fields[i].name ="SCS[1:0]* Address Remap"; fields[i++].dwOffset = 0x0d0;
  78.         fields[i].name ="SCS[3:2]* Address Remap"; fields[i++].dwOffset = 0x0d8;
  79.         fields[i].name ="CS[2:0]* Remap"; fields[i++].dwOffset = 0x0e0;
  80.         fields[i].name ="CS[3]* & Boot CS* Remap"; fields[i++].dwOffset = 0x0e8;
  81.         fields[i].name ="PCI_0 IO Remap"; fields[i++].dwOffset = 0x0f0;
  82.         fields[i].name ="PCI_0 Memory 0 Remap"; fields[i++].dwOffset = 0x0f8;
  83.         fields[i].name ="PCI_0 Memory 1 Remap"; fields[i++].dwOffset = 0x100;
  84.         fields[i].name ="PCI_1 IO Remap"; fields[i++].dwOffset = 0x108;
  85.         fields[i].name ="PCI_1 Memory 0 Remap"; fields[i++].dwOffset = 0x110;
  86.         fields[i].name ="PCI_1 Memory 1 Remap"; fields[i++].dwOffset = 0x118;
  87.         //CPU Sync Barrier
  88.         group[j].name ="CPU Sync Barrier"; group[j++].iPosition = i;
  89.         fields[i].name ="PCI_0 Sync Barrier Virtual Register"; fields[i++].dwOffset = 0x0c0;
  90.         fields[i].name ="PCI_1 Sync Barrier Virtual Register"; fields[i++].dwOffset = 0x0c8;
  91.     }
  92.     //DRAM and Device Address Space
  93.     group[j].name ="DRAM and Device Address Space"; group[j++].iPosition = i;
  94.     fields[i].name ="RAS[0] Low Decode Address"; fields[i++].dwOffset = 0x400;
  95.     fields[i].name ="RAS[0] High Decode Address"; fields[i++].dwOffset = 0x404;
  96.     fields[i].name ="RAS[1] Low Decode Address"; fields[i++].dwOffset = 0x408;
  97.     fields[i].name ="RAS[1] High Decode Address"; fields[i++].dwOffset = 0x40c;
  98.     fields[i].name ="RAS[2] Low Decode Address"; fields[i++].dwOffset = 0x410;
  99.     fields[i].name ="RAS[2] High Decode Address"; fields[i++].dwOffset = 0x414;
  100.     fields[i].name ="RAS[3] Low Decode Address"; fields[i++].dwOffset = 0x418;
  101.     fields[i].name ="RAS[3] High Decode Address"; fields[i++].dwOffset = 0x41c;
  102.     fields[i].name ="CS[0] Low Decode Address"; fields[i++].dwOffset = 0x420;
  103.     fields[i].name ="CS[0] High Decode Address"; fields[i++].dwOffset = 0x424;
  104.     fields[i].name ="CS[1] Low Decode Address"; fields[i++].dwOffset = 0x428;
  105.     fields[i].name ="CS[1] High Decode Address"; fields[i++].dwOffset = 0x42c;
  106.     fields[i].name ="CS[2] Low Decode Address"; fields[i++].dwOffset = 0x430;
  107.     fields[i].name ="CS[2] High Decode Address"; fields[i++].dwOffset = 0x434;
  108.     fields[i].name ="CS[3] Low Decode Address"; fields[i++].dwOffset = 0x438;
  109.     fields[i].name ="CS[3] High Decode Address"; fields[i++].dwOffset = 0x43c;
  110.     fields[i].name ="Boot CS Low Decode Address"; fields[i++].dwOffset = 0x440;
  111.     fields[i].name ="Boot CS High Decode Address"; fields[i++].dwOffset = 0x444;
  112.     fields[i].name ="Address Decode Error"; fields[i++].dwOffset = 0x470;
  113.     //DRAM Configuration
  114.     group[j].name ="DRAM Configuration"; group[j++].iPosition = i;
  115.     if (f111)
  116.     {
  117.         fields[i].name ="DRAM Configuration"; fields[i++].dwOffset = 0x448;
  118.     }
  119.     else
  120.     {
  121.         fields[i].name ="SDRAM Bank0 Parameters"; fields[i++].dwOffset = 0x44c;
  122.         fields[i].name ="SDRAM Bank1 Parameters"; fields[i++].dwOffset = 0x450;
  123.         fields[i].name ="SDRAM Bank2 Parameters"; fields[i++].dwOffset = 0x454;
  124.         fields[i].name ="SDRAM Bank3 Parameters"; fields[i++].dwOffset = 0x458;
  125.     }
  126.     //DRAM Parameters
  127.     group[j].name ="DRAM Parameters"; group[j++].iPosition = i;
  128.     fields[i].name ="DRAM Bank0 Parameters"; fields[i++].dwOffset = 0x44c;
  129.     fields[i].name ="DRAM Bank1 Parameters"; fields[i++].dwOffset = 0x450;
  130.     fields[i].name ="DRAM Bank2 Parameters"; fields[i++].dwOffset = 0x454;
  131.     fields[i].name ="DRAM Bank3 Parameters"; fields[i++].dwOffset = 0x458;
  132.     //Device Parameters
  133.     group[j].name ="Device Parameters"; group[j++].iPosition = i;
  134.     fields[i].name ="Device Bank0 Parameters"; fields[i++].dwOffset = 0x45c;
  135.     fields[i].name ="Device Bank1 Parameters"; fields[i++].dwOffset = 0x460;
  136.     fields[i].name ="Device Bank2 Parameters"; fields[i++].dwOffset = 0x464;
  137.     fields[i].name ="Device Bank3 Parameters"; fields[i++].dwOffset = 0x468;
  138.     fields[i].name ="Device Boot Bank Parameters"; fields[i++].dwOffset = 0x46c;
  139.     if (f130)
  140.     {
  141.         // ECC
  142.         group[j].name ="ECC"; group[j++].iPosition = i;
  143.         fields[i].name ="ECC Upper_Data"; fields[i++].dwOffset = 0x480;
  144.         fields[i].name ="ECC Lower Data"; fields[i++].dwOffset = 0x484;
  145.         fields[i].name ="ECC From Memory"; fields[i++].dwOffset = 0x488;
  146.         fields[i].name ="ECC Calculeted"; fields[i++].dwOffset = 0x48c;
  147.         fields[i].name ="ECC Error Report"; fields[i++].dwOffset = 0x490;
  148.     }
  149.     //DMA Record
  150.     group[j].name ="DMA Record"; group[j++].iPosition = i;
  151.     fields[i].name ="Channel 0 DMA Byte Count"; fields[i++].dwOffset = 0x800;
  152.     fields[i].name ="Channel 1 DMA Byte Count"; fields[i++].dwOffset = 0x804;
  153.     fields[i].name ="Channel 2 DMA Byte Count"; fields[i++].dwOffset = 0x808;
  154.     fields[i].name ="Channel 3 DMA Byte Count"; fields[i++].dwOffset = 0x80c;
  155.     fields[i].name ="Channel 0 DMA Source Address"; fields[i++].dwOffset = 0x810;
  156.     fields[i].name ="Channel 1 DMA Source Address"; fields[i++].dwOffset = 0x814;
  157.     fields[i].name ="Channel 2 DMA Source Address"; fields[i++].dwOffset = 0x818;
  158.     fields[i].name ="Channel 3 DMA Source Address"; fields[i++].dwOffset = 0x81c;
  159.     fields[i].name ="Channel 0 DMA Destination Address"; fields[i++].dwOffset = 0x820;
  160.     fields[i].name ="Channel 1 DMA Destination Address"; fields[i++].dwOffset = 0x824;
  161.     fields[i].name ="Channel 2 DMA Destination Address"; fields[i++].dwOffset = 0x828;
  162.     fields[i].name ="Channel 3 DMA Destination Address"; fields[i++].dwOffset = 0x82c;
  163.     fields[i].name ="Channel 0 Next Record Pointer"; fields[i++].dwOffset = 0x830;
  164.     fields[i].name ="Channel 1 Next Record Pointer"; fields[i++].dwOffset = 0x834;
  165.     fields[i].name ="Channel 2 Next Record Pointer"; fields[i++].dwOffset = 0x838;
  166.     fields[i].name ="Channel 3 Next Record Pointer"; fields[i++].dwOffset = 0x83c;
  167.     if (f120 || f130)
  168.     {
  169.         fields[i].name ="Channel 0 Current Descriptor Pointer"; fields[i++].dwOffset = 0x870;
  170.         fields[i].name ="Channel 1 Current Descriptor Pointer"; fields[i++].dwOffset = 0x874;
  171.         fields[i].name ="Channel 2 Current Descriptor Pointer"; fields[i++].dwOffset = 0x878;
  172.         fields[i].name ="Channel 3 Current Descriptor Pointer"; fields[i++].dwOffset = 0x87c;
  173.     }
  174.     //DMA Channel Control
  175.     group[j].name ="DMA Channel Control"; group[j++].iPosition = i;
  176.     fields[i].name ="Channel 0 Control"; fields[i++].dwOffset = 0x840;
  177.     fields[i].name ="Channel 1 Control"; fields[i++].dwOffset = 0x844;
  178.     fields[i].name ="Channel 2 Control"; fields[i++].dwOffset = 0x848;
  179.     fields[i].name ="Channel 3 Control"; fields[i++].dwOffset = 0x84c;
  180.     //DMA Arbiter
  181.     group[j].name ="DMA Arbiter"; group[j++].iPosition = i;
  182.     fields[i].name ="Arbiter Control"; fields[i++].dwOffset = 0x860;
  183.     //Timer Counter
  184.     group[j].name ="Timer Counter"; group[j++].iPosition = i;
  185.     fields[i].name ="Timer /Counter 0"; fields[i++].dwOffset = 0x850;
  186.     fields[i].name ="Timer /Counter 1"; fields[i++].dwOffset = 0x854;
  187.     fields[i].name ="Timer /Counter 2"; fields[i++].dwOffset = 0x858;
  188.     fields[i].name ="Timer /Counter 3"; fields[i++].dwOffset = 0x85c;
  189.     fields[i].name ="Timer /Counter Control"; fields[i++].dwOffset = 0x864;
  190.     //PCI Internal
  191.     group[j].name ="PCI Internal"; group[j++].iPosition = i;
  192.     if (f111)
  193.     {
  194.         fields[i].name ="Command"; fields[i++].dwOffset = 0xc00;
  195.         fields[i].name ="Time Out & Retry"; fields[i++].dwOffset = 0xc04;
  196.         fields[i].name ="RAS[1:0] Bank Size"; fields[i++].dwOffset = 0xc08;
  197.         fields[i].name ="RAS[3:2] Bank Size"; fields[i++].dwOffset = 0xc0c;
  198.         fields[i].name ="CS[2:0] Bank Size"; fields[i++].dwOffset = 0xc10;
  199.         fields[i].name ="CS[3] & Boot CS Bank Size"; fields[i++].dwOffset = 0xc14;
  200.         fields[i].name ="SErr Mask"; fields[i++].dwOffset = 0xc28;
  201.         fields[i].name ="Interrupt Acknowledge"; fields[i++].dwOffset = 0xc34;
  202.         fields[i].name ="Base Address Registers Enable"; fields[i++].dwOffset = 0xc3c;
  203.         fields[i].name ="Configuration Address"; fields[i++].dwOffset = 0xcf8;
  204.         fields[i].name ="Configuration Data"; fields[i++].dwOffset = 0xcfc;
  205.     }
  206.     else
  207.     {
  208.         fields[i].name ="PCI_0 Command"; fields[i++].dwOffset = 0xc00;
  209.         fields[i].name ="PCI_1 Command"; fields[i++].dwOffset = 0xc80;
  210.         fields[i].name ="PCI_0 Time Out & Retry"; fields[i++].dwOffset = 0xc04;
  211.         fields[i].name ="PCI_1 Time Out & Retry"; fields[i++].dwOffset = 0xc84;
  212.         fields[i].name ="PCI_0 SCS[1:0]* Bank Size"; fields[i++].dwOffset = 0xc08;
  213.         fields[i].name ="PCI_1 SCS[1:0]* Bank Size"; fields[i++].dwOffset = 0xc88;
  214.         fields[i].name ="PCI_0 SCS[3:2]* Bank Size"; fields[i++].dwOffset = 0xc0c;
  215.         fields[i].name ="PCI_1 SCS[3:2]* Bank Size"; fields[i++].dwOffset = 0xc8c;
  216.         fields[i].name ="PCI_0 CS[2:0]* Bank Size"; fields[i++].dwOffset = 0xc10;
  217.         fields[i].name ="PCI_1 CS[2:0]* Bank Size"; fields[i++].dwOffset = 0xc90;
  218.         fields[i].name ="PCI_0 CS[3]* & Boot CS* Bank Size"; fields[i++].dwOffset = 0xc14;
  219.         fields[i].name ="PCI_1 CS[3]* & Boot CS* Bank Size"; fields[i++].dwOffset = 0xc94;
  220.         fields[i].name ="PCI_0 Base Address RegistersÆ Enable"; fields[i++].dwOffset = 0xc3c;
  221.         fields[i].name ="PCI_1 Base Address RegistersÆ Enable"; fields[i++].dwOffset = 0xcbc;
  222.         fields[i].name ="PCI_0 Prefetch/Max Burst Size"; fields[i++].dwOffset = 0xc40;
  223.         fields[i].name ="PCI_1 Prefetch/Max Burst Size"; fields[i++].dwOffset = 0xcc0;
  224.         fields[i].name ="PCI_0 SCS[1:0]* Base Address Remap"; fields[i++].dwOffset = 0xc48;
  225.         fields[i].name ="PCI_1 SCS[1:0]* Base Address Remap"; fields[i++].dwOffset = 0xcc8;
  226.         fields[i].name ="PCI_0 SCS[3:2]* Base Address Remap"; fields[i++].dwOffset = 0xc4c;
  227.         fields[i].name ="PCI_1 SCS[3:2]* Base Address Remap"; fields[i++].dwOffset = 0xccc;
  228.         fields[i].name ="PCI_0 CS[2:0]* Base Address Remap"; fields[i++].dwOffset = 0xc50;
  229.         fields[i].name ="PCI_1 CS[2:0]* Base Address Remap"; fields[i++].dwOffset = 0xcd0;
  230.         fields[i].name ="PCI_0 CS[3]* & Boot CS* Address Remap"; fields[i++].dwOffset = 0xc54;
  231.         fields[i].name ="PCI_1 CS[3]* & Boot CS* Address Remap"; fields[i++].dwOffset = 0xcd4;
  232.         fields[i].name ="PCI_0 Swapped SCS[1:0]* Base Address Remap"; fields[i++].dwOffset = 0xc58;
  233.         fields[i].name ="PCI_1 Swapped SCS[1:0]* Base Address Remap"; fields[i++].dwOffset = 0xcd8;
  234.         fields[i].name ="PCI_0 Swapped SCS[3:2]* Base Address Remap"; fields[i++].dwOffset = 0xc5c;
  235.         fields[i].name ="PCI_1 Swapped SCS[3:2]* Base Address Remap"; fields[i++].dwOffset = 0xcdc;
  236.         fields[i].name ="PCI_0 Swapped CS[3]* & BootCS* Base Address Remap"; fields[i++].dwOffset = 0xc64;
  237.         fields[i].name ="PCI_1 Swapped CS[3]* & BootCS* Base Address Remap"; fields[i++].dwOffset = 0xce4;
  238.         fields[i].name ="PCI_0 Configuration Address"; fields[i++].dwOffset = 0xcf8;
  239.         fields[i].name ="PCI_1 Configuration Address"; fields[i++].dwOffset = 0xcf0;
  240.         fields[i].name ="PCI_0 Configuration Data Virtual Register"; fields[i++].dwOffset = 0xcfc;
  241.         fields[i].name ="PCI_1 Configuration Data Virtual Register"; fields[i++].dwOffset = 0xcf4;
  242.     }
  243.     //Interrupts
  244.     group[j].name ="Interrupts"; group[j++].iPosition = i;
  245.     fields[i].name ="Interrupt Cause"; fields[i++].dwOffset = 0xc18;
  246.     if (f111)
  247.     {
  248.         fields[i].name ="CPU/Local Master Mask"; fields[i++].dwOffset = 0xc1c;
  249.         fields[i].name ="PCI Mask"; fields[i++].dwOffset = 0xc24;
  250.         fields[i].name ="SErr Mask"; fields[i++].dwOffset = 0xc28;
  251.         fields[i].name ="Interrupt Acknowledge"; fields[i++].dwOffset = 0xc34;
  252.     }
  253.     else
  254.     {
  255.         fields[i].name ="High Interrupt Cause Register"; fields[i++].dwOffset = 0xc98;
  256.         fields[i].name ="CPU Interrupt Mask Register"; fields[i++].dwOffset = 0xc1c;
  257.         fields[i].name ="CPU High Interrupt Mask Register"; fields[i++].dwOffset = 0xc9c;
  258.         fields[i].name ="PCI_0 Interrupt Cause Mask Register"; fields[i++].dwOffset = 0xc24;
  259.         fields[i].name ="PCI_0 High Interrupt Cause Mask Register"; fields[i++].dwOffset = 0xca4;
  260.         fields[i].name ="PCI_0 SErr0 Mask"; fields[i++].dwOffset = 0xc28;
  261.         fields[i].name ="PCI_1 SErr1 Mask"; fields[i++].dwOffset = 0xca8;
  262.         fields[i].name ="PCI_0 Interrupt Acknowledge Virtual Register"; fields[i++].dwOffset = 0xc34;
  263.         fields[i].name ="PCI_1 Interrupt Acknowledge Virtual Register"; fields[i++].dwOffset = 0xc30;
  264.         fields[i].name ="CPU Select Cause Register"; fields[i++].dwOffset = 0xc70;
  265.         fields[i].name ="PCI_0 Interrupt Select Register"; fields[i++].dwOffset = 0xc74;
  266.     }
  267.     group[j].iPosition = i;
  268.     iGroupNum = j;
  269.     iFieldsNum = i;
  270.  
  271.     do
  272.     {
  273.         int group_row = 0;
  274.  
  275.         printf ("\n");
  276.         printf ("Edit Galileo 64 registers\n");
  277.         printf ("----------------------------\n");
  278.         while (group_row<iGroupNum)
  279.         {
  280.             printf ("%2d. %s\n", group_row+1, group[group_row].name);
  281.             group_row++;
  282.         }
  283.         printf ("99. Back to main menu\n");
  284.         printf ("Choose group of registers to read from / write to, or 99 to exit: ");
  285.         cmd = 0;
  286.         fgets(line, sizeof(line), stdin);
  287.         sscanf (line, "%d",&cmd);
  288.         if (cmd>=1 && cmd <=group_row)
  289.         {
  290.             j = cmd-1;
  291.             do
  292.             {
  293.                 int fields_row = group[j].iPosition;
  294.  
  295.                 printf ("\n");
  296.                 printf ("Edit Galileo 64 %s registers\n", group[j].name);
  297.                 printf ("--------------------------------------------------\n");
  298.                 i = 1;
  299.                 while (fields_row<group[j+1].iPosition)
  300.                 {   
  301.                     char buf[10];
  302.                     fields[fields_row].dwVal = GT64_ReadReg(hGT, fields[fields_row].dwOffset);
  303.                     sprintf(buf, "%08x",fields[fields_row].dwVal);
  304.                     printf ("%2d. %-30s : %s     \n",i, fields[fields_row].name, buf);
  305.                     fields_row++;
  306.                     i++;
  307.                 }
  308.                 printf ("99. Back to previous menu\n");
  309.                 printf ("Choose register to write to, or 99 to exit: ");
  310.                 cmd2 = 0;
  311.                 fgets(line, sizeof(line), stdin);
  312.                 sscanf (line, "%d",&cmd2);
  313.                 if (cmd2>=1 && cmd2<=fields_row - group[j].iPosition)
  314.                 {
  315.                     i = cmd2 - 1 + group[j].iPosition;
  316.                     printf 
  317.                         ("Enter value to write to %s register (or 'X' to cancel)\n> ",fields[i].name);
  318.                     fgets(line, sizeof(line), stdin);
  319.                     if (toupper (line[0])!='X')
  320.                     {
  321.                         DWORD dwVal;
  322.                         dwVal = 0;
  323.                         sscanf (line,"%x",&dwVal);
  324.                         GT64_WriteReg(hGT, fields[i].dwOffset, dwVal);
  325.                     }
  326.                 }
  327.             } while (cmd2!=99);
  328.         }
  329.     } while (cmd!=99);
  330. }
  331.  
  332. char *GT64_GetAddrRangeName(GT64_ADDR addrSpace)
  333. {
  334.     return 
  335.         addrSpace==GT64_ADDR_BAR0 ? "RAS [1:0] - (BAR0)" :
  336.         addrSpace==GT64_ADDR_BAR1 ? "RAS [3:2] - (BAR1)" :
  337.         addrSpace==GT64_ADDR_BAR2 ? "CS [2:0] - (BAR2)" :
  338.         addrSpace==GT64_ADDR_BAR3 ? "BootCS/Cs3 - (BAR3)" :
  339.         addrSpace==GT64_ADDR_BAR4 ? "Internal Registers (Memory) - (BAR4)" :
  340.         addrSpace==GT64_ADDR_BAR5 ? "Internal Registers (I/O) - (BAR5)" : "Invalid";
  341. }
  342.  
  343. void GT64_BoardAccess(GT64_HANDLE hGT)
  344. {
  345.     int cmd, cmd2;
  346.     DWORD addr, data, i;
  347.     GT64_ADDR ad_sp = GT64_ADDR_BAR0;
  348.  
  349.     for (; ad_sp<=GT64_ADDR_BAR5 && !GT64_IsAddrSpaceActive(hGT, ad_sp); ad_sp++)
  350.     if (ad_sp>GT64_ADDR_BAR5)
  351.     {
  352.         printf ("No active memory spaces on board!\n");
  353.         return;
  354.     }
  355.  
  356.     do
  357.     {
  358.         printf ("Access the board's offset ranges\n");
  359.         printf ("--------------------------------\n");
  360.         printf ("(Access to invalid offset may hang the computer!)\n");
  361.         printf ("1. Change active memory space: %s\n",GT64_GetAddrRangeName(ad_sp));
  362.         printf ("2. Read from board\n");
  363.         printf ("3. Write to board\n");
  364.         printf ("99. Back to main menu\n");
  365.         printf ("\n");
  366.         printf ("Enter option: ");
  367.         cmd = 0;
  368.         fgets(line, sizeof(line), stdin);
  369.         sscanf (line, "%d",&cmd);
  370.         switch (cmd)
  371.         {
  372.         case 1:
  373.             printf ("Choose memory space:\n");
  374.             printf ("--------------------\n");
  375.             for (i=GT64_ADDR_BAR0; i<=GT64_ADDR_BAR5; i++)
  376.             {
  377.                 printf ("%d. %s", i, GT64_GetAddrRangeName(i));
  378.                 if (GT64_IsAddrSpaceActive(hGT, i)) printf ("\n");
  379.                 else printf (" - space not active\n");
  380.             }
  381.             printf ("Enter option: ");
  382.             cmd2 = 99;
  383.             fgets(line, sizeof(line), stdin);
  384.             sscanf (line, "%d",&cmd2);
  385.             if (cmd2>=GT64_ADDR_BAR0 && cmd2<=GT64_ADDR_BAR5)
  386.             {
  387.                 int new_ad_sp = cmd2;
  388.                 if (GT64_IsAddrSpaceActive(hGT, new_ad_sp)) ad_sp = new_ad_sp;
  389.                 else printf ("Chosen space not active!\n");
  390.             }
  391.             break;
  392.         case 2:
  393.             printf ("Enter offset to read from: ");
  394.             fgets(line, sizeof(line), stdin);
  395.             sscanf (line, "%x", &addr);
  396.             data = GT64_ReadDWord(hGT, ad_sp, addr);
  397.             printf ("Value read: %x\n", data);
  398.             break;
  399.         case 3:
  400.             printf ("Enter offset to write to: ");
  401.             fgets(line, sizeof(line), stdin);
  402.             sscanf (line, "%x", &addr);
  403.             printf ("Enter data to write : ");
  404.             fgets(line, sizeof(line), stdin);
  405.             sscanf (line, "%x",&data);
  406.             GT64_WriteDWord(hGT, ad_sp, addr, data);
  407.             break;
  408.         }
  409.     } while (cmd!=99);
  410. }
  411.  
  412. void WINAPI GT64_IntHandlerRoutine(GT64_HANDLE hGT, GT64_INT_RESULT *intResult)
  413. {
  414.     printf ("Got interrupt number %d\n", intResult->dwCounter);
  415. }
  416.  
  417. void GT64_EnableDisableInterrupts(GT64_HANDLE hGT)
  418. {
  419.     int cmd;
  420.  
  421.     do
  422.     {
  423.         printf ("Enable / Disable interrupts\n");
  424.         printf ("---------------------------\n");
  425.         printf ("1. %s interrupts\n", GT64_IntIsEnabled(hGT) ? "Disable" : "Enable");
  426.         printf ("99. Back to main menu\n");
  427.         printf ("\n");
  428.         printf ("Enter option: ");
  429.         cmd = 0;
  430.         fgets(line, sizeof(line), stdin);
  431.         sscanf (line, "%d",&cmd);
  432.         switch (cmd)
  433.         {
  434.         case 1:
  435.             if (GT64_IntIsEnabled(hGT))
  436.             {
  437.                 printf ("Disabling interrupt Int\n");
  438.                 GT64_IntDisable(hGT);
  439.             }
  440.             else
  441.             {
  442.                 printf ("Enabling interrupts\n");
  443.                 if (!GT64_IntEnable(hGT, GT64_IntHandlerRoutine))
  444.                     printf ("failed enabling interrupts\n");
  445.             }
  446.             break;
  447.         }
  448.     } while (cmd!=99);
  449. }
  450.  
  451.  
  452. GT64_HANDLE GT64_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID, BOOL fUseInt)
  453. {
  454.     DWORD cards, my_card;
  455.     GT64_HANDLE hGT = NULL;
  456.     GT64_VERSION gt64Ver;
  457.     DWORD i;
  458.  
  459.     if (dwVendorID==0)
  460.     {
  461.         printf ("Enter VendorID: ");
  462.         fgets(line, sizeof(line), stdin);
  463.         sscanf (line, "%x",&dwVendorID);
  464.         if (dwVendorID==0) return NULL;
  465.  
  466.         printf ("Enter DeviceID: ");
  467.         fgets(line, sizeof(line), stdin);
  468.         sscanf (line, "%x",&dwDeviceID);
  469.         if (dwDeviceID==0) return NULL;
  470.     }
  471.  
  472.     cards = GT64_CountCards (dwVendorID, dwDeviceID);
  473.     if (cards==0) 
  474.     {
  475.         printf("%s", GT64_ErrorString);
  476.         return NULL;
  477.     }
  478.     else if (cards==1) my_card = 1;
  479.     else
  480.     {
  481.         printf("Found %d matching PCI cards\n", cards);
  482.         printf("Select card (1-%d): ", cards);
  483.         i = 0;
  484.         fgets(line, sizeof(line), stdin);
  485.         sscanf (line, "%d",&i);
  486.         if (i>=1 && i <=cards) my_card = i;
  487.         else 
  488.         {
  489.             printf ("Choice out of range\n");
  490.             return NULL;
  491.         }
  492.     }
  493.     printf("Enter your bridge type:\n");
  494.     printf("1. GT-64111\n");
  495.     printf("2. GT-64120\n");
  496.     printf("3. GT-64130\n");
  497.     i = 0;
  498.     fgets(line, sizeof(line), stdin);
  499.     sscanf (line, "%d",&i);
  500.     switch (i) 
  501.     {
  502.         case 1:
  503.             gt64Ver = GT64_VERSION_64111;
  504.             break;
  505.         case 2:
  506.             gt64Ver = GT64_VERSION_64120;
  507.             break;
  508.         case 3:
  509.             gt64Ver = GT64_VERSION_64130;
  510.             break;
  511.         default:
  512.             printf ("Choice out of range\n");
  513.             return NULL;
  514.     }
  515.     if (GT64_Open (&hGT, gt64Ver, dwVendorID, dwDeviceID, my_card - 1, fUseInt ? GT64_OPEN_USE_INT : 0))
  516.         printf ("Galileo 64 PCI card found!\n");
  517.     else printf ("%s", GT64_ErrorString);
  518.     return hGT;
  519. }
  520.  
  521. int main(int argc, char *argv[])
  522. {
  523.     int cmd;
  524.     GT64_HANDLE hGT = NULL;
  525.     HANDLE hWD;
  526.     BOOL fUseInt = FALSE; // by default - do not install interrupts
  527.  
  528.     printf ("Galileo 64 diagnostic utility.\n");
  529.     printf ("Application accesses hardware using " WD_PROD_NAME ".\n");
  530.  
  531.     // make sure WinDriver is loaded
  532.     if (!PCI_Get_WD_handle(&hWD)) return 0;
  533.     WD_Close (hWD);
  534.  
  535.     hGT = GT64_LocateAndOpenBoard(0x11ab, 0, fUseInt);
  536.     do
  537.     {
  538.         printf ("\n");
  539.         printf ("Galileo 64 main menu\n");
  540.         printf ("-------------------\n");
  541.         printf ("1. Scan PCI bus\n");
  542.         printf ("2. Set opening board %s interrupts\n", fUseInt ? "without" : "with");
  543.         printf ("3. Locate/Choose Galileo 64 board (%s interrupts)\n", fUseInt ? "with" : "without");
  544.         if (hGT)
  545.         {
  546.             printf ("4. PCI configuration registers\n");
  547.             printf ("5. Galileo 64 local registers\n");
  548.             printf ("6. Access address spaces on the board\n");
  549.             if (hGT->fUseInt)
  550.                 printf ("7. Enable / Disable interrupts\n");
  551.         }
  552.         printf ("99. Exit\n");
  553.         printf ("Enter option: ");
  554.         cmd = 0;
  555.         fgets(line, sizeof(line), stdin);
  556.         sscanf (line, "%d",&cmd);
  557.         switch (cmd)
  558.         {
  559.         case 1: // Scan PCI bus
  560.             PCI_Print_all_cards_info();
  561.             break;
  562.         case 2: // Set open board with / without interrupts
  563.             fUseInt = !fUseInt;
  564.             break;
  565.         case 3: // Locate Galileo 64 board
  566.             if (hGT) GT64_Close(hGT);
  567.             hGT = GT64_LocateAndOpenBoard(0, 0, fUseInt);
  568.             if (!hGT) printf ("GT64 card open failed!\n");
  569.             break;
  570.         case 4: // PCI configuration registers
  571.             if (hGT) PCI_EditConfigReg(hGT->pciSlot);
  572.             break;
  573.         case 5: // Galileo 64 local registers
  574.             if (hGT) GT64_EditReg(hGT);
  575.             break;
  576.         case 6: // Access address spaces on the board
  577.             if (hGT) GT64_BoardAccess(hGT);
  578.             break;
  579.        case 7: // Enable / Disable interrupts
  580.             if (hGT && hGT->fUseInt) GT64_EnableDisableInterrupts(hGT);
  581.             break;
  582.         }
  583.     } while (cmd!=99);
  584.  
  585.     if (hGT) GT64_Close(hGT);
  586.  
  587.     return 0;
  588. }
  589.  
  590.                                       
  591.